package com.mcptt.config.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.cloudptt.api.comm.Common;
import com.mcptt.db.model.AddrInfo;

public class ImsInfo implements Parcelable
{
	private String impi = null;
	private String impu = null;
//	private String realm = null;
	private String sbc = null;
	private String dns = null;

	private String domain = null;
	private String psiCms ="sip:cms@crsc.mcx.mnc020.mcc460.5gr";
	private String psiGms = "sip:gms@crsc.mcx.mnc020.mcc460.5gr";
	private String psiMcptt = "sip:mcptt@crsc.mcx.mnc020.mcc460.5gr";
	private String psiMcvideo = "sip:mcvideo@crsc.mcx.mnc020.mcc460.5gr";
	private String psiMcdata = "sip:mcdata@crsc.mcx.mnc020.mcc460.5gr";

	public ImsInfo(String impi,String impu)
	{
		this.impi = impi;
		this.impu = impu;
	}

	public void updateImsInfo(String impi,String impu)
	{
		this.impi = impi;
		this.impu = impu;
	}

	public void updateImsSbc(String sbc,String dns)
	{
		this.sbc = sbc;
		this.dns = dns;
	}

	public void updatePsi(String domain,String psiCms,String psiGms,String psiMcptt,String psiMcvideo,String psiMcdata)
	{
		this.domain = domain;
		this.psiCms = psiCms;//AddrInfo.toMcxPsi(psiCms,domain);
		this.psiGms = psiGms;//AddrInfo.toMcxPsi(psiGms,domain);;
		this.psiMcptt = psiMcptt;//AddrInfo.toMcxPsi(psiMcptt,domain);;
		this.psiMcvideo = psiMcvideo;//AddrInfo.toMcxPsi(psiMcvideo,domain);;
		this.psiMcdata = psiMcdata;//AddrInfo.toMcxPsi(psiMcdata,domain);;
	}

	public boolean isInvalid()
	{
		if(this.impi == null
				|| this.impi.length() <= 0
				|| this.impu == null
				|| this.impu.length() <= 0
//				|| this.realm == null
//				|| this.realm.length() <= 0
				|| this.sbc == null
				|| this.sbc.length() <= 0)
		{
			return true;
		}
		return false;
	}

	public boolean checkMustParamOk()
	{
		if(impi == null
				|| impi.length() <= 0)
		{
			return false;
		}
		if(impu == null
				|| impu.length() <= 0)
		{
			return false;
		}
//	if(psi == null
//		|| psi.length() <= 0)
//	{
//	    return false;
//	}
		return true;
	}
	public String getDomain() {
		return domain;
	}
	public String getImpi()
	{
		return impi;
	}
	public String getImpu()
	{
		return impu;
	}
	public String getSbc() {
		return sbc;
	}
	public String getDns() {
		return dns;
	}
	public String getPsiCms() {
		return psiCms;
	}

	public String getPsiGms() {
		return psiGms;
	}

	public String getPsiMcvideo() {
		return psiMcvideo;
	}

	public String getPsiMcptt() {
		return psiMcptt;
	}

	public String getPsiMcdata() {
		return psiMcdata;
	}

	public String toImpi(String mcId)
	{
		return AddrInfo.toImsImpi(mcId,domain);
	}
	public String toImpu(String mcId)
	{
		return AddrInfo.toImsImpu(mcId,domain);
	}


	public String toString()
	{
		StringBuffer buffer = new StringBuffer("ImsInfo:");
		buffer.append("impi = ").append(impi).append(",");
		buffer.append("impu = ").append(impu).append(",");
		buffer.append("sbc = ").append(sbc).append(";");
		buffer.append("dns = ").append(dns).append(";");

		buffer.append("domain = ").append(domain).append(";");
		buffer.append("psiCms = ").append(psiCms).append(",");
		buffer.append("psiGms = ").append(psiGms).append(",");
		buffer.append("psiMcptt = ").append(psiMcptt).append(";");
		buffer.append("psiMcvideo = ").append(psiMcvideo).append(",");
		buffer.append("psiMcdata = ").append(psiMcdata).append(",");

		return buffer.toString();
	}

	public static final Parcelable.Creator<ImsInfo> CREATOR = new Parcelable.Creator<ImsInfo>() {
		public ImsInfo createFromParcel(Parcel in) {
			return new ImsInfo(in);
		}

		public ImsInfo[] newArray(int size) {
			return new ImsInfo[size];
		}
	};

	private ImsInfo(Parcel in)
	{
		impi = getReadParcelableString(in.readString());
		impu = getReadParcelableString(in.readString());
		sbc = getReadParcelableString(in.readString());
		dns = getReadParcelableString(in.readString());

		domain = getReadParcelableString(in.readString());
		psiCms = getReadParcelableString(in.readString());
		psiGms = getReadParcelableString(in.readString());
		psiMcptt = getReadParcelableString(in.readString());
		psiMcvideo = getReadParcelableString(in.readString());
		psiMcdata = getReadParcelableString(in.readString());
	}

	private String getWriteParcelableString(String str) {
		return (str == null) ? "null" : str;
	}
	private String getReadParcelableString(String str) {
		return str.equalsIgnoreCase("null") ? null : str;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeString(getWriteParcelableString(impi));
		dest.writeString(getWriteParcelableString(impu));
		dest.writeString(getWriteParcelableString(sbc));
		dest.writeString(getWriteParcelableString(dns));

		dest.writeString(getWriteParcelableString(domain));
		dest.writeString(getWriteParcelableString(psiCms));
		dest.writeString(getWriteParcelableString(psiGms));
		dest.writeString(getWriteParcelableString(psiMcptt));
		dest.writeString(getWriteParcelableString(psiMcvideo));
		dest.writeString(getWriteParcelableString(psiMcdata));
	}
}
